Decimal To Binary Algorithm
In computing and electronic systems, binary-coded decimal (BCD) is a class of binary encodings of decimal numbers where each decimal digit is represented by a fixed number of bits, normally four or eight. In byte-oriented systems (i.e. most modern computers), the term unpacked BCD normally imply a full byte for each digit (often including a sign), whereas packed BCD typically encodes two decimal digits within a individual byte by take advantage of the fact that four bits are enough to represent the range 0 to 9.
// This function convert decimal to binary number
//
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter a number:";
cin >> number;
int remainder, binary = 0, var = 1;
do
{
remainder = number % 2;
number = number / 2;
binary = binary + (remainder * var);
var = var * 10;
} while (number > 0);
cout << "the binary is :";
cout << binary;
cout << endl;
return 0;
}